#ifndef ROSyncProperty_H
#define ROSyncProperty_H

#include <QObject>
#include <QtQmlIntegration>

#include "ROSyncObject.h"
#include "ROPropertyUpdater.h"

class ROHost;
class ROHostPrivate;
class RONodePrivate;
class DxSOPropertyObserver;

//属性同步，在上面定义的属性会在客户端和服务端之间同步

class ROSyncProperty:public ROSyncObject
{
    Q_OBJECT
    QML_NAMED_ELEMENT(ROSyncProperty)
public:
    ROSyncProperty(QObject* parent = nullptr);

    ROPropertyUpdater *updater() const;
    void setUpdater(ROPropertyUpdater *newUpdater);

    virtual QStringList allProperties() = 0;//所有的属性
signals:
    void updaterChanged();
    void propertyChanged(QString prop);//属性改变信号
protected:
    void initialize() override;
    virtual QVariantMap extractProperties(const QStringList& prop) = 0;//提取出所有的属性
    virtual void handleProperties(const QVariantMap& var) = 0;//处理所有的属性
    void validateUpdater();
    void updateAllProperty(bool safe);//将所有属性同步给客户端
    void updateProperties(const QStringList& properties,bool safe);//同步一部分属性
private:
    QObject* m_reg = nullptr;
    QPointer<ROPropertyUpdater> m_updater;//决定属性更新方案，默认值为ROHost的TriggeredUpdater
    friend class ROHost;
    friend class ROHostPrivate;
    friend class RONodePrivate;
    friend class DxSOPropertyObserver;
    friend class ROPropertyUpdater;
    Q_PROPERTY(ROPropertyUpdater *updater READ updater WRITE setUpdater NOTIFY updaterChanged FINAL)
};

#endif
